//
//  WMTabBarController.swift
//  swift微博项目
//
//  Created by 王明 on 15/11/8.
//  Copyright © 2015年 王明. All rights reserved.
//

import UIKit

class WMTabBarController: UITabBarController {
    
    @objc private func composeDidClick() {
        print(__FUNCTION__)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        //首先tabbar是只读，所以要重写kvc方法
        
        let maintabBar = WMMainTabbar()
        //赋值，
        setValue(maintabBar, forKey: "tabBar")
        //添加子视图控制器
        addChildViewControllers()
        
        //打印函数的类名
        
        
        //添加点击事件
        maintabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
        
        
        }
    
     private func addChildViewControllers(){
    
        addChildViewController(WMHomeController() , title : "首页" , imageName: "tabbar_home")
        addChildViewController(WMMessageController(), title : "消息" , imageName:"tabbar_message_center")
        addChildViewController(WMDiscoverController(),title : "发现" , imageName:"tabbar_discover")
        addChildViewController(WMProfileController(),title : "我" , imageName:"tabbar_profile")
    
    }
    
    
    //重载
    func addChildViewController(vc : UIViewController , title : String , imageName:String){
    
    //实例化导航视图
        let nav = UINavigationController(rootViewController: vc)
        
        nav.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
    
    
    }
    
        
        
    }

    

   


